<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.security.MessageDigest" %>
<%@ page import="java.security.NoSuchAlgorithmException" %>
<%@ page import="java.math.BigInteger" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>保存数据</title>
</head>
<body>

	<%
	//接收from数据
	request.setCharacterEncoding("UTF-8");
	String name = request.getParameter("name");
	String phone = request.getParameter("phone");
	String pwd = request.getParameter("pwd");
	
	 // 定义加密后的密码变量
    String encryptedPassword = "";

    try {
        // 创建MessageDigest实例，并指定加密算法为MD5
        MessageDigest md = MessageDigest.getInstance("MD5");
        
        // 更新加密内容
        md.update(pwd.getBytes());
        
        // 获取加密后的字节数组
        byte[] digest = md.digest();
        
        // 将字节数组转换为16进制字符串
        encryptedPassword = new BigInteger(1, digest).toString(16);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
	
	//连接数据库
	Class.forName("org.mariadb.jdbc.Driver");
	Connection conn = DriverManager.getConnection("jdbc:mariadb://localhost:3306/mealdb?user=root&password=1230321");
	Statement stmt = conn.createStatement();

	//构造SQL写入数据到数据表
	String sql = "INSERT INTO customers(name,phone,pwd) VALUES('" + name + "','" + phone + "','" + encryptedPassword +"')";
	System.out.print("sql= " + sql);
	out.print("响应行数： " + stmt.executeUpdate(sql));

	stmt.close();
	conn.close();

	//返回列页面
	out.print("修改完毕！");
	response.sendRedirect("customerlogin.jsp");
	%>


</body>
</html>